package com.study;

import com.study.servlet.HelloServlet;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

public class ServletContextServer {
    public static void main(String[] args) throws Exception {
        Server server = new Server(8080);

        ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);

        servletContextHandler.setContextPath("/");
        server.setHandler(servletContextHandler);

        //// http://localhost:8080/hello
        servletContextHandler.addServlet(new ServletHolder(new HelloServlet()), "/hello");
        //// http://localhost:8080/hello
        servletContextHandler.addServlet(new ServletHolder(new HelloServlet("my msg")), "/hello/msg");

        //// http://localhost:8080/hello
        servletContextHandler.addServlet(new ServletHolder(new HelloServlet()), "/goodbye");
        //// http://localhost:8080/hello
        servletContextHandler.addServlet(new ServletHolder(new HelloServlet("my goodbye msg")), "/goodbye/msg");


        server.start();
        server.join();  //将子线程添加到主线程中。
    }
}
